package com.mianyang.zhangsan.controller;

import com.mianyang.zhangsan.common.annotation.SaveLog;
import com.mianyang.zhangsan.common.base.BaseController;
import com.mianyang.zhangsan.common.base.R;
import com.mianyang.zhangsan.model.dto.SecLoginDto;
import com.mianyang.zhangsan.model.dto.SecRegisterDto;
import com.mianyang.zhangsan.model.entity.SecAccount;
import com.mianyang.zhangsan.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jiangjr
 * @date 2022-10-23
 */
@RestController
@RequestMapping("/user")
public class SecLoginController extends BaseController {

    @Autowired
    private LoginService loginService;

    /**
     * 登录
     */
    @SaveLog(title = "登录模块", content = "用户登录")
    @PostMapping("/login")
    public R login(@RequestBody SecAccount account) {
        SecLoginDto info = loginService.login(account);
        return success("loginInfo", info);
    }

    /**
     * 注册服务
     */
    @PostMapping("/register")
    public R register(@RequestBody SecAccount account) {
        SecRegisterDto info = loginService.register(account);
        return success("registerInfo", info);
    }
}
